﻿using CommandLib;
using SignalrChat.DbServer;
using SignalrChat.Models;

namespace SignalrChat.Buesses
{
    public class UsersBll
    {
        bool IsLiteDB = false;
        public UsersBll()
        {
            IsLiteDB = AppSettings.GetSection<Boolean>("LiteDB");
        }
        public List<Users> GetUsers()
        {
            if (IsLiteDB)
            {
                return LiteUsersDao.GetUsers();
            }
            else
                return UsersDao.GetUsers();
        }

        public Users getById(Guid Id)
        {
            if (IsLiteDB)
            {
                return LiteUsersDao.getById(Id);
            }
            else
                return UsersDao.getById(Id);
        }

        public bool AddUsers(Users users)
        {
            if (users == null)
            {
                return false;
            }
            users.Id = Guid.NewGuid();
            users.CreateTime = DateTime.Now;
            if (IsLiteDB)
            {
                return LiteUsersDao.AddUsers(users);
            }
            else
                return UsersDao.AddUsers(users);
        }

        public bool UpdateUsers(Users users)
        {
            if (users == null) { return false; }
            if (IsLiteDB)
            {
                return LiteUsersDao.UpdateUsers(users);
            }
            else
                return UsersDao.UpdateUsers(users);
        }
        public bool UpdateLoginTime(Guid Id, DateTime dateTime)
        {
            if (IsLiteDB)
            {
                return LiteUsersDao.UpdateLoginTime(Id, dateTime);
            }
            else
                return UsersDao.UpdateLoginTime(Id, dateTime);
        }
        public bool DeleteUsers(Guid Id)
        {
            if (IsLiteDB)
            {
                return LiteUsersDao.DeleteUsers(Id);
            }
            else
                return UsersDao.DeleteUsers(Id);
        }
    }
}
